const dbConfig = require("../utils/dbconfig");

/**
 * 获取分类
 * @param req
 * @param res
 */
module.exports.getCate = (req, res) => {
    let sql = 'SELECT * FROM cate';
    let sqlArr = '';
    let callback = (err, result) => {
        if (err) {
            console.log('数据库连接出错', err);
        } else {
            res.send({
                'list': result
            })
        }
    }
    dbConfig.sqlConnection(sql, sqlArr, callback);
}

/**
 * 获取指定分类的文章列表
 * @param req
 * @param res
 */
module.exports.getPostCate = (req, res) => {
    let {id} = req.query,
        sql = `SELECT * FROM post WHERE cate_id=?`,
        sqlArr = [id];
    let callback = (err, result) => {
        if (err) {
            console.log('数据库连接出错', err);
        } else {
            res.send({
                'list': result
            })
        }
    }
    dbConfig.sqlConnection(sql, sqlArr, callback);
}

